package com.example.ai_basedintelligentdiagnosisandtreatmentofchildren.adapter;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.example.ai_basedintelligentdiagnosisandtreatmentofchildren.R;
import com.example.ai_basedintelligentdiagnosisandtreatmentofchildren.model.MedicineItem;

import java.util.List;

public class MedicineItemAdapter extends RecyclerView.Adapter<MedicineItemAdapter.MedicineViewHolder> {

    private List<MedicineItem> medicineItemList;
    private OnItemClickListener onItemClickListener;

    public interface OnItemClickListener{
        void onItemClick(int postion);
    }

    public void setOnItemClickListener(OnItemClickListener onItemClickListener){
        this.onItemClickListener=onItemClickListener;
    }

    public MedicineItemAdapter(List<MedicineItem> medicineItemList) {
        this.medicineItemList = medicineItemList;
    }

    @NonNull
    @Override
    public MedicineViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_patient_information, parent, false);
        return new MedicineViewHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull MedicineViewHolder holder, int position) {
        MedicineItem item = medicineItemList.get(position);
        holder.patientName.setText(item.getPatientName());
        holder.time.setText(item.getTime());
        holder.diseaseName.setText(item.getDiseaseName());
        holder.itemView.setOnClickListener(v->{
            if(onItemClickListener !=null){
                onItemClickListener.onItemClick(position);
            }
        });
    }

    @Override
    public int getItemCount() {
        return medicineItemList.size();
    }

    public static class MedicineViewHolder extends RecyclerView.ViewHolder {
        ImageView imageView;
        TextView patientName;
        TextView time;
        TextView diseaseName;

        public MedicineViewHolder(@NonNull View view) {
            super(view);
            imageView = view.findViewById(R.id.imageView);
            patientName = view.findViewById(R.id.patientName);
            time = view.findViewById(R.id.time);
            diseaseName = view.findViewById(R.id.diseaseName);
        }
    }
}
